using DG.Tweening;
using GameLogic;
using System.Collections;
using System.Collections.Generic;
using TEngine;
using UnityEngine;
using UnityEngine.UI;

public class TimeUI : MonoBehaviour
{
    public Image seasonImage;
    public Text dateText;
    public Text timeText;

    private List<GameObject> clockBlocks = new List<GameObject>();

    private void Awake()
    {
    }

    private void OnEnable()
    {
        GameEvent.AddEventListener(ILoginUI_Event.OnDayChange, OnDayChange);
        GameEvent.AddEventListener(ILoginUI_Event.OnSeasonChange, OnSeasonChange);
    }

    private void OnDisable()
    {
        GameEvent.RemoveEventListener(ILoginUI_Event.OnDayChange, OnDayChange);
        GameEvent.RemoveEventListener(ILoginUI_Event.OnSeasonChange, OnSeasonChange);
    }

    public void OnDayChange()
    {
        //TODO切换后每天的比列是不一样的
    }


    private void OnGameMinuteEvent(int minute, int hour, int day, Season season)
    {
        timeText.text = hour.ToString("00") + ":" + minute.ToString("00");
    }

    private void OnSeasonChange()
    {
        switch (EnhancedTimeWeatherSystem.Instance.GetCurrentSeason())
        {
            case Season.春天:
                seasonImage.sprite= GameModule.Resource.LoadAsset<Sprite>("ui_time_12");
                break;
            case Season.夏天:
                seasonImage.sprite = GameModule.Resource.LoadAsset<Sprite>("ui_time_13");
                break;
            case Season.秋天:
                seasonImage.sprite = GameModule.Resource.LoadAsset<Sprite>("ui_time_14");
                break;
            case Season.冬天:
                seasonImage.sprite = GameModule.Resource.LoadAsset<Sprite>("ui_time_15");
                break;
            default:
                break;
        }
    }

    /// <summary>
    /// 根据小时切换时间块显示
    /// </summary>
    /// <param name="hour"></param>
    private void SwitchHourImage(int hour)
    {
        int index = (hour) / 4;

        if (index == 0)
        {
            foreach (var item in clockBlocks)
            {
                item.SetActive(false);
            }
        }
        else
        {
            for (int i = 0; i < clockBlocks.Count; i++)
            {
                if (i < index)
                    clockBlocks[i].SetActive(true);
                else
                    clockBlocks[i].SetActive(false);
            }
        }
    }
}
